package mytest.leetcode;

public class P121 {

    public static void main(String[] args) {

        int[] prices = {7, 1, 5, 3, 6, 4};

        int minPrice = Integer.MAX_VALUE;
        int maxPrice = Integer.MIN_VALUE;

        for(int i = 0; i < prices.length; i++) {
           if (prices[i] < minPrice) {
               minPrice = prices[i];
           } else if (prices[i] - minPrice > maxPrice) {
               maxPrice = prices[i] - minPrice;
           }
        }
        System.out.println(maxPrice);
    }

}
